﻿using System.Text;
using System.Web.Mvc;
using Exercise2.Models;
using System.Web.Mvc.Html;

namespace Exercise2.Helpers
{
    public static class ListHelpers
    {
        public static string RenderList(this HtmlHelper htmlHelper, object value)
        {
            ClimbList list = value as ClimbList;
            if (list == null)
                return "";
            StringBuilder builder = new StringBuilder();
            if (list.Count == 0)
                return "<div style=\"border: 1px solid red\">" +
                        "No climbs to display</div>";
            builder.Append("<div style=\"border: 1px solid red\"><ul>");
            foreach (Climb climb in list)
            {
                builder.AppendFormat("<li>{0}</li>",
                    htmlHelper.ActionLink(climb.Name, "Climb", new { name = climb.Name }));
            }
            builder.Append("</ul></div>");
            return builder.ToString();
        }
    }
}
